<div class="bjui-pageHeader">
    <table class="table table-bordered table-hover table-striped table-top">
        <!-- 商品名称 	商品货号 	数量(2) 	零售单价 	颜色规格  -->
        <tr>
            <th>商品名称</th>
            <th>商品货号</th>
            <th>数量</th>
            <th>零售单价</th>
            <th>颜色规格</th>
            <!--<th>支付金额</th>-->
            <!--<th>支付积分</th>-->
        </tr>
        <?php foreach($importOrderGoodsList as $orderGoodsArr):?>
        <tr>
            <td>{$orderGoodsArr.order_goods_name}</td>
            <td>{$orderGoodsArr.goods_sn}</td>
            <td>{$orderGoodsArr.goods_number}</td>
            <td>{$orderGoodsArr.goods_price}</td>
            <td>{$orderGoodsArr.goods_color},{$orderGoodsArr.goods_size}</td>
            <!--<td>{$orderGoodsArr.pay_money}</td>
            <td>{$orderGoodsArr.pay_integral}</td>-->
        </tr>
        <?php endforeach;?>
    </table>
    <form id="pagerForm" data-toggle="ajaxsearch" action="{:U('searchGoods')}" method="post">
        <!-- <input type="hidden" name="inputName" value="{:I('request.inputName')}"> -->
        <input type="hidden" name="orderId" value="{:I('request.orderId')}">
        <input type="hidden" name="orderGoodsId" value="{:I('request.orderGoodsId')}">
		<input type="hidden" name="orderStatus" value="{:I('request.orderStatus')}">
        <div class="bjui-searchBar">
            <select name="key" data-toggle="selectpicker">
                <option value="name"
                <?php echo I("key")=="name" ? "selected='true'" : "";?>>名称</option>
                <option value="sn"
                <?php echo I("key")=="sn" ? "selected='true'" : "";?>>货号</option>
                <!-- <option value="bar_code"
                <?php echo I("key")=="bar_code" ? "selected='true'" : "";?>>条码</option>
                -->
            </select>
            <input type="text" value="{:I('goodsName')|I('value')}" name="value" size="30">
            <button type="submit" class="btn-default" data-icon="search">查询</button>
            <a class="btn btn-orange" href="javascript:;"
               onclick="$.CurrentDialog.dialog('reloadForm', true, {type:'GET',data:{orderId:'{:I('request.orderId')}',orderStatus:'{:I('request.orderStatus')}'}})"
               data-icon="undo">返回</a>
        </div>
    </form>
</div>
<div class="bjui-pageContent tableContent">
    <table class="table table-bordered table-hover table-striped table-top" id="searchContent">
        <?php if(empty($list)):?>
            <thead>
            <tr>
                <th>商品名称</th>
                <th>单价</th>
                <th>零售价</th>
                <th>数量</th>
                <th align="center">操作</th>
            </tr>
            </thead>
            <tbody>
            <?php if($orderGoodsList):?>
                <?php foreach($orderGoodsList as $orderGoodsArr):?>
                <tr>
                    <td>
                        {$orderGoodsArr.goods_name}
                        <br />
                        货号：{$orderGoodsArr.goods_sn}
                    </td>
                    <td>{$orderGoodsArr.goods_price}</td>
                    <td>{$orderGoodsArr.retail_price}</td>
                    <td>{$orderGoodsArr.goods_number}</td>
                    <td align="center">
                        颜色：{$orderGoodsArr.color_name}，规格：{$orderGoodsArr.spec_name}
                        <hr style="border-top:1px solid #185598; margin: 5px;" />
                        {$orderGoodsArr.bar_code}
                        <br />
                        <if condition="$_REQUEST['orderStatus'] neq '10' ">
                        <a type="button" class="btn btn-red"
                           href="{:U('delGoods?navTabId=Order'.$orderGoodsArr['order_id'].'&orderId='.$orderGoodsArr['order_id'].'&orderGoodsId='.$orderGoodsArr['order_goods_id'].'&barCodeId='.$orderGoodsArr['bar_code_id'])}"
                           data-toggle="doajax" data-confirm-msg="确认删除该商品？"
                           data-callback="delGoodsCallBack">删除</a>
                        </if>
                        <a class="btn btn-green" href="{:U('searchBarCode?goodsId='.$orderGoodsArr['goods_id'].'&orderGoodsId='.$orderGoodsArr['id'])}"
                           data-toggle="ajaxload" data-target="#searchContent">修改</a>
                    </td>
                    <input type="hidden" name="barCodeId" value="{$orderGoodsArr.id}">
                    <input type="hidden" name="goodsId" value="{$orderGoodsArr.goods_id}">
                </tr>
                <?php endforeach;?>
            <?php else:?>
            <tr>
                <td colspan="5" align="center">没有添加商品!</td>
            </tr>
            <?php endif;?>
            </tbody>
        <?php else:?>
            <thead>
            <tr>
                <th>商品名称</th>
            </tr>
            </thead>
            <tbody>
            <?php foreach($list as $arr):?>
            <tr>
                <td>
                    <a href="{:U('searchBarCode?goodsId='.$arr['id'])}"
                       data-toggle="ajaxload" data-target="#searchContent">{$arr.name}</a>
                </td>
            </tr>
            <?php endforeach;?>
            </tbody>
        <?php endif;?>
    </table>
</div>
<script>

    /**
     * [chooseBarCode 选择对应的条码商品]
     * @param  {[type]} obj [description]
     * @return {[type]}     [description]
     */
    function chooseBarCode(obj, orderGoodsId) {
        var tableBarCode = $(obj).parent().parent();
		var orderStatus = "{:I('request.orderStatus')}";
        var options = {};
        options['url'] = "{:U('Order/addGoods')}";
        options['type'] = "POST";
		if(orderStatus > 0)
		{
			options['callback'] = "addGoodsCallBack2";
		}else
		{
		 options['callback'] = "addGoodsCallBack";
		}
        options['data'] = {};
        options['data']['order_id'] = "{:I('request.orderId')}";   // 订单id
        options['data']['order_goods_id'] = orderGoodsId;   // order_goods表id
		options['data']['status'] = "{:I('request.orderStatus')}";  // 订单状态
        options['data']['number'] = tableBarCode.find("input[type=text][data-toggle=spinner]").spinner().val();
        options['data']['retail_price'] = tableBarCode.find("input[type=text][name=retail_price]").val();
        options['data']['bar_code_id'] = tableBarCode.find("input[type=hidden][name=barCodeId]").val();
        options['data']['goods_id'] = tableBarCode.find("input[type=hidden][name=goodsId]").val();
        console.log(options['data']);
        if (!options['data']['number'] || options['data']['number']==0 ||options['data']['number']=='0') {
            $(this).alertmsg('error', '商品数量不能为0');
            return;
        }
        $(obj).bjuiajax('doAjax', options);
    }

	/**
     * 添加商品回调函数
     * @param data
     */
    function addGoodsCallBack2(data) { // data为返回的数据
        if (data && data[BJUI.keys.statusCode] == BJUI.statusCode.ok) {
//            $.CurrentDialog.dialog('closeCurrent'); // 关闭当前弹窗
            $.CurrentDialog.dialog('reload'); // 关闭当前弹窗
			$.CurrentNavtab.navtab('reload');          // 刷新当前窗口
        } else {
            $(this).alertmsg('error', data.message);
        }
    }
	
	
</script>